package Equals;

class Student {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object obj) {
        if ( obj == null ) {
            return false;
        }
        if ( this == obj ) {
            return true;
        }
        if(! (obj instanceof Student)) {
            return false;
        }
        Student student = (Student)obj;
        if(this.name.equals(student.name)) {
            return true;
        }
        return false;
    }
}

public class Test {
    public static void main(String[] args) {
        Student student1 = new Student("张三",18);
        Student student2 = new Student("张三",25);
        if(student1.equals(student2)) {
            System.out.println(student1+"和"+student2+"是同一个人！");
        }
    }


}
